<template>
  <div class="posReport">
    <CommonBtn label-name="POS门店清单报告管理" v-if="!button || (button.event!='add()' && button.event!='edit()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl"@tableSelect="tableSelect"  :conditions="conditions"></CommonList>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_POSRETAILERLIST_EXPORT" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import moment from 'moment';
    export default {
        name:'posReport',
        data(){
            return{
                nowTime: new Date(),
                year:0,
                buttons:[
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'storeId',
                        label:'Store_ID',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'vendor',
                        label:'Vendor',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'storeCode',
                        label:'Store_Code',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'soldTo',
                        label:'SOLDTO'
                    },
                    {
                        prop:'mdmCode',
                        label:'统一代码-新',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'isSFA',
                        label:'是否覆盖SFA'
                    },
                    {
                        prop:'retailName',
                        label:'CUSTNAME-OUTLET',
                        label1:'CUSTNAME-OUTLET',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'buName',
                        label:'BU'
                    },
                    {
                        prop:'customNameCN',
                        label:'account',
                        label1:'account',
                        search:true,
                        type:'search',
                        searchUrl:this.$api.API_SELECT_CUSTOMER_GROUP_INFO,
                        searchLabel:'客户集团',
                        searchProxy:'customNameCN',
                        searchValue:'pkid',
                        proxy:'customNameCN',
                        queryProp:'fkRetailGroup',
                        columns:[
                            {
                                prop:'customCode',
                                label:'客户集团编码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customNameCN',
                                label:'集团中文名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customNameEN',
                                label:'集团英文名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'accountCode',
                                label:'预算Account',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customTypeName',
                                label:'集团分类',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop:'customTypeCode',
                                        label:'集团类型编码',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop:'customTypeName',
                                        label:'集团类型名称',
                                        search:true,
                                        type:'text'
                                    },
                                    {
                                        prop:'valid',
                                        label:'是否有效',
                                        search:true,
                                        type:'checkbox'
                                    }
                                ],
                                searchUrl:this.$api.API_CUSTOMERCLASSIFY_LIST,
                                searchLabel:'客户集团分类',
                                searchProxy:'customTypeCode',
                                searchValue:'pkid',
                                queryProp:'fkCustomType'
                            },
                            {
                                prop:'isValid',
                                label:'是否有效',
                                search:true,
                                type:'checkbox'
                            }
                        ]
                    },
                    {
                        prop:'areaName',
                        label:'current_area',
                        label1:'current_area',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'regionName',
                                label:'区域名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'regionCode',
                                label:'区域代码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'zoneName',
                                label:'大区名称',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop: 'zoneName',
                                        label: '大区名称',
                                        type:'text',
                                        search:true
                                    },{
                                        prop: 'zoneCode',
                                        label: '大区代码',
                                        type:'text',
                                        search:true
                                    },{
                                        prop: 'isValid',
                                        label: '是否有效'
                                    }
                                ],
                                searchUrl:this.$api.API_QUERYZONE,
                                searchLabel:'大区信息',
                                proxy:'zoneName',
                                searchProxy:'zoneName',
                                queryProp:'fkZone',
                                searchValue:'pkid'
                            },
                            {
                                prop:'isValid',
                                label:'是否有效'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYREGION,
                        searchLabel:'大区信息',
                        proxy:'areaName',
                        searchProxy:'regionName',
                        queryProp:'fkArea',
                        searchValue:'pkid'
                    },
                    {
                        prop:'cityName',
                        label:'CITY',
                        label1:'CITY',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'cityTypeName',
                        label:'CITYTYPE'
                    },
                    {
                        prop:'provinceName',
                        label:'省',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'regionName',
                        label:'current_region',
                        label1:'current_region',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop: 'zoneName',
                                label: '大区名称',
                                type:'text',
                                search:true
                            },{
                                prop: 'zoneCode',
                                label: '大区代码',
                                type:'text',
                                search:true
                            },{
                                prop: 'isValid',
                                label: '是否有效'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYZONE,
                        searchLabel:'大区信息',
                        proxy:'regionName',
                        searchProxy:'zoneName',
                        queryProp:'fkRegion',
                        searchValue:'pkid'
                    },
                    // {
                    //     prop:'accountGroupName',
                    //     label:'预算Account组'
                    // },
                    // {
                    //     prop:'custgrpc',
                    //     label:'CUSTGRPC',
                    //     search:true,
                    //     type:'text'
                    // },
                    {
                        prop:'retailTypeName',
                        label:'CUSTGRPC',
                        search:true,
                        type:'text',
                    },
                    {
                        prop:'customerSupplyType',
                        label:'CustomerSupplyType'
                    },
                    {
                        prop:'businessYear',
                        label:'Opening-Year'
                    },
                    {
                        prop:'businessMonth',
                        label:'Opening-Month'
                    },
                    {
                        prop:'businessYearMonth',
                        label:'Opening-Year&Month'
                    },
                    {
                        prop:'remark',
                        label:'Remark'
                    },
                    {
                        prop:'soldToCode',
                        label:'sold-to code'
                    },
                    {
                        prop:'smmsName',
                        label:'sold-to name'
                    },
                    {
                        prop:'posRetailerType',
                        label:'门店类型',
                        search:true,
                        type:'text',
                        //searchOnly:true
                    },
                    {
                        prop:'shelfTypeA',
                        label:'婴儿货架类型',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'shelfTypeB',
                        label:'沐浴露货架类型',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'oldAreaName',
                        label:'LY_area',
                        label1:'LY_area',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'regionName',
                                label:'区域名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'regionCode',
                                label:'区域代码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'zoneName',
                                label:'大区名称',
                                search:true,
                                type:'search',
                                columns:[
                                    {
                                        prop: 'zoneName',
                                        label: '大区名称',
                                        type:'text',
                                        search:true
                                    },{
                                        prop: 'zoneCode',
                                        label: '大区代码',
                                        type:'text',
                                        search:true
                                    },{
                                        prop: 'isValid',
                                        label: '是否有效'
                                    }
                                ],
                                searchUrl:this.$api.API_QUERYZONE,
                                searchLabel:'大区信息',
                                proxy:'zoneName',
                                searchProxy:'zoneName',
                                queryProp:'fkZone',
                                searchValue:'pkid'
                            },
                            {
                                prop:'isValid',
                                label:'是否有效'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYREGION,
                        searchLabel:'大区信息',
                        proxy:'areaName',
                        searchProxy:'regionName',
                        queryProp:'OldArea',
                        searchValue:'regionName'
                    },
                    {
                        prop:'oldRegionName',
                        label:'LY_region',
                        label1:'LY_region',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop: 'zoneName',
                                label: '大区名称',
                                type:'text',
                                search:true
                            },{
                                prop: 'zoneCode',
                                label: '大区代码',
                                type:'text',
                                search:true
                            },{
                                prop: 'isValid',
                                label: '是否有效'
                            }
                        ],
                        searchUrl:this.$api.API_QUERYZONE,
                        searchLabel:'大区信息',
                        proxy:'regionName',
                        searchProxy:'zoneName',
                        queryProp:'OldRegion',
                        searchValue:'zoneName'
                    },
                    {
                        prop:'locationName',
                        label:'Location',
                        search:true,
                        type:'text',
                    },
                    {
                        prop:'cdccCode',
                        label:'J_Store_Code_Old',
                        search:true,
                        type:'text'
                    },

                ],
                listUrl:this.$api.API_SELECT_POSRETAILER_LIST,
                button:{},
                conditions:[],
                row:{}
            }
        },
        created() {
           this.getYear()
        },
        methods:{
            onButtonClick(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            getYear(){
               this.year=this.nowTime.getFullYear();
               var lastyear=this.year-1;
               for(let item of this.columns){
                //    if (item.prop=='areaName') {
                //        item.label=this.year+' Area';
                //        item.label1=this.year+' Area'
                //    }
                //    if (item.prop=='regionName') {
                //        item.label=this.year+' Region';
                //        item.label1=this.year+' Region'
                //    }
                //    if (item.prop=='oldAreaName') {
                //        item.label=lastyear+' AREA';
                //        item.label1=lastyear+' AREA'
                //    }
                //    if (item.prop=='oldRegionName') {
                //        item.label=lastyear+' Region';
                //        item.label1=lastyear+' Region'
                //    }
               }
            }
        },
        components:{CommonExport, SearchPopUp,CommonList,CommonBtn}
    }
</script>
